package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevLiftDao;
import com.sugon.entity.SpecialDevLiftEntity;
import com.sugon.service.SpecialDevLiftService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-电梯台账Service实现类
 *
 * @author sugon
 * @date 2021-09-08 16:30:39
 */
@Service("specialDevLiftService")
public class SpecialDevLiftServiceImpl implements SpecialDevLiftService {
    @Autowired
    private SpecialDevLiftDao specialDevLiftDao;

    @Override
    public SpecialDevLiftEntity queryObject(String id) {
        return specialDevLiftDao.queryObject(id);
    }

    @Override
    public List<SpecialDevLiftEntity> queryList(Map<String, Object> map) {
        return specialDevLiftDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevLiftDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevLiftDao.getLastestEquipmentCode(ErmsCodePrefix.LIFT_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.LIFT_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevLiftEntity specialDevLift) {
        specialDevLift.setId(RandomUtil.randomString(32));
        specialDevLift.setGmtCreate(DateUtil.date());
        specialDevLift.setCreateUser(ShiroUtils.getUserId());
        specialDevLift.setEquipmentCode(generateUniqueCode());
        return specialDevLiftDao.save(specialDevLift);
    }

    @Override
    public int update(SpecialDevLiftEntity specialDevLift) {
        specialDevLift.setGmtModified(DateUtil.date());
        specialDevLift.setUpdateUser(ShiroUtils.getUserId());
        return specialDevLiftDao.update(specialDevLift);
    }

    @Override
    public int delete(String id) {
        return specialDevLiftDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevLiftDao.deleteBatch(ids);
    }
}
